package com.atguigu.gulimall.product.web;

import com.atguigu.gulimall.product.entity.CategoryEntity;
import com.atguigu.gulimall.product.service.CategoryService;
import com.atguigu.gulimall.product.vo.CateLog2Vo;
import org.apache.http.HttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {
    @Autowired
    CategoryService categoryService;
    @GetMapping({"/","index.html"})
public String index(Model model, HttpServletRequest request) {
       List<CategoryEntity> categoryEntities = categoryService.getLevel1CategoryService();
        request.getSession(true);
       model.addAttribute("categories", categoryEntities);
        return "index";
    }
    @ResponseBody
    @GetMapping("index/catalog.json")
    public Map<String, List<CateLog2Vo>> getCataLogJson(){
        Map<String, List<CateLog2Vo>> map=categoryService.getCataLogJson();
        return map;
    }
    @ResponseBody
    @GetMapping("/test")
    public String test(HttpSession session){

        return session.getAttribute("login").toString();
    }
}
